<template>
  <div style="width: 100%; height: 100%">
    <div id="main" style="width: 100%; height: 500px"></div>
    <el-cascader
      :options="options"
      clearable
      v-model="scoreTime"
      @change="change"
    ></el-cascader>
    <el-table
      :data="
        tableData.filter(
          (data) =>
            !search || data.name.toLowerCase().includes(search.toLowerCase())
        )
      "
      border
      style="width: 100%"
    >
      <el-table-column label="学号" prop="student_Number"> </el-table-column>
      <el-table-column label="姓名" prop="studentName"> </el-table-column>
      <el-table-column label="时间" prop="time"> </el-table-column>
      <el-table-column label="综测总分" prop="scoreSum"> </el-table-column>
      <el-table-column label="班级排名" prop="ranking"> </el-table-column>
      <el-table-column align="right">
        <template slot="header" slot-scope="scope">
          <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import * as echarts from "echarts/core";
import {
  TitleComponent,
  TooltipComponent,
  LegendComponent,
} from "echarts/components";
import { PieChart } from "echarts/charts";
import { LabelLayout } from "echarts/features";
import { CanvasRenderer } from "echarts/renderers";
echarts.use([
  TitleComponent,
  TooltipComponent,
  LegendComponent,
  PieChart,
  CanvasRenderer,
  LabelLayout,
]);
export default {
  name: "Home",
  data() {
    const userInfo = JSON.parse(localStorage.getItem("userInfo"));
    return {
      scoreTime: ["大一", "一"],
      search: "",
      tableData: [],
      form: {
        student_Number: "",
        password: "",
        SecondaryCollege: "",
        className: "",
        studentName: "",
        grade: "",
      },
      classList: [],
      chart: null,
      option: {
        title: {
          text: "班级综测提交情况",
          subtext: userInfo.className,
          left: "center",
        },
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          left: "left",
        },
        series: [
          {
            name: "综测数据",
            type: "pie",
            radius: "50%",
            data: [
              { value: 0, name: "审核通过" },
              { value: 0, name: "已提交" },
              { value: 0, name: "未提交" },
              { value: 0, name: "审核不通过" },
              { value: 0, name: "未审核" },
            ],
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      },
      options: [
        {
          value: "大一",
          label: "大一",
          children: [
            {
              value: "一",
              label: "一",
            },
            {
              value: "二",
              label: "二",
            },
          ],
        },
        {
          value: "大二",
          label: "大二",
          children: [
            {
              value: "一",
              label: "一",
            },
            {
              value: "二",
              label: "二",
            },
          ],
        },
        {
          value: "大三",
          label: "大三",
          children: [
            {
              value: "一",
              label: "一",
            },
            {
              value: "二",
              label: "二",
            },
          ],
        },
        {
          value: "大四",
          label: "大四",
          children: [
            {
              value: "一",
              label: "一",
            },
            {
              value: "二",
              label: "二",
            },
          ],
        },
      ],
    };
  },
  created() {
    this.getRanking(this.scoreTime);
  },
  mounted() {
    var chartDom = document.getElementById("main");
    var myChart = echarts.init(chartDom);
    this.option && myChart.setOption(this.option, "dark");
  },
  methods: {
    change(value) {
      this.getRanking(value);
      var chartDom = document.getElementById("main");
      var myChart = echarts.init(chartDom);
      this.option && myChart.setOption(this.option, "dark");
    },
    getRanking(value) {
      const userInfo = JSON.parse(localStorage.getItem("userInfo"));
      this.form.className = userInfo.className;
      this.tableData = [];
      this.$request
        .get("/getRankingList/getRanking", {
          params: {
            page: 1,
            pagesize: 10,
            className: userInfo.className,
            grade: value[0],
            semester: value[1],
            SecondaryCollege: userInfo.SecondaryCollege,
          },
        })
        .then(({ data }) => {
          if (data.data.rankingList && data.data.rankingList.length > 0) {
            data.data.rankingList
              .filter((ite) => {
                return ite.AdminProcess === "审核通过";
              })
              .sort((a, b) => {
                return (
                  b.scoreList.ComprehensiveSurveyTotalScore -
                  a.scoreList.ComprehensiveSurveyTotalScore
                );
              })
              .forEach((item, index) => {
                this.tableData.push({
                  student_Number: item.student_Number,
                  ranking: index + 1,
                  studentName: item.studentName,
                  scoreSum: item.scoreList.ComprehensiveSurveyTotalScore,
                  time: item.schoolYear + "第" + item.semester + "学期",
                });
              });
            const res1 = data.data.rankingList.filter((item) => {
              return item.AdminProcess === "审核通过";
            });
            const res2 = data.data.rankingList.filter((item) => {
              return item.yesOrNoSubmit;
            });
            const res3 = data.data.rankingList.filter((item) => {
              return item.AdminProcess === "审核不通过";
            });
            const res4 = data.data.rankingList.filter((item) => {
              return !item.AdminProcess;
            });
            this.option.series[0].data = [
              { value: res1.length, name: "审核通过" },
              { value: res2.length, name: "已提交" },
              {
                value:
                  data.data.tatol -
                  (res1.length + res2.length + res3.length + res4.length),
                name: "未提交",
              },
              { value: res3.length, name: "审核不通过" },
              { value: res4.length, name: "未审核" },
            ];
            console.log(this.option.series[0].data);
            return;
          }
          this.tableData = [];
        });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>